home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / hplip / ui4 / printsettingstoolbox.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  44KB  |  1,448 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. from base.g import *
  6. from base import utils
  7. from prnt import cups
  8. from base.codes import *
  9. from ui_utils import *
  10. from PyQt4.QtCore import *
  11. from PyQt4.QtGui import *
  12.  
  13. class RangeValidator(QValidator):
  14.     
  15.     def __init__(self, parent = None, name = None):
  16.         QValidator.__init__(self, parent)
  17.  
  18.     
  19.     def validate(self, input, pos):
  20.         for x in unicode(input)[pos - 1:]:
  21.             if x not in u'0123456789,- ':
  22.                 return (QValidator.Invalid, pos)
  23.         
  24.         return (QValidator.Acceptable, pos)
  25.  
  26.  
  27.  
  28. class PinValidator(QValidator):
  29.     
  30.     def __init__(self, parent = None, name = None):
  31.         QValidator.__init__(self, parent)
  32.  
  33.     
  34.     def validate(self, input, pos):
  35.         for x in unicode(input)[pos - 1:]:
  36.             if x not in u'0123456789':
  37.                 return (QValidator.Invalid, pos)
  38.         
  39.         return (QValidator.Acceptable, pos)
  40.  
  41.  
  42.  
  43. class UsernameAndJobnameValidator(QValidator):
  44.     
  45.     def __init__(self, parent = None, name = None):
  46.         QValidator.__init__(self, parent)
  47.  
  48.     
  49.     def validate(self, input, pos):
  50.         for x in unicode(input)[pos - 1:]:
  51.             if x in u' /=,.:;\'"[]{}-+!@#$%^&*()':
  52.                 return (QValidator.Invalid, pos)
  53.         
  54.         return (QValidator.Acceptable, pos)
  55.  
  56.  
  57.  
  58. class OptionComboBox(QComboBox):
  59.     
  60.     def __init__(self, rw, parent, name, group, option, choices, default, typ = cups.PPD_UI_PICKONE, other = None, job_option = False):
  61.         QComboBox.__init__(self, parent)
  62.         self.group = group
  63.         self.option = option
  64.         self.choices = choices
  65.         self.default = default
  66.         self.typ = typ
  67.         self.other = other
  68.         self.job_option = job_option
  69.         self.setObjectName(name)
  70.  
  71.     
  72.     def setDefaultPushbutton(self, pushbutton):
  73.         self.pushbutton = pushbutton
  74.  
  75.     
  76.     def setOther(self, other):
  77.         self.other = other
  78.  
  79.  
  80.  
  81. class OptionSpinBox(QSpinBox):
  82.     
  83.     def __init__(self, parent, name, group, option, default, job_option = False):
  84.         QSpinBox.__init__(self, parent)
  85.         self.group = group
  86.         self.option = option
  87.         self.default = default
  88.         self.job_option = job_option
  89.         self.setObjectName(name)
  90.  
  91.     
  92.     def setDefaultPushbutton(self, pushbutton):
  93.         self.pushbutton = pushbutton
  94.  
  95.  
  96.  
  97. class OptionRadioButton(QRadioButton):
  98.     
  99.     def __init__(self, parent, name, group, option, default, job_option = False):
  100.         QRadioButton.__init__(self, parent)
  101.         self.group = group
  102.         self.option = option
  103.         self.default = default
  104.         self.job_option = job_option
  105.         self.setObjectName(name)
  106.  
  107.     
  108.     def setDefaultPushbutton(self, pushbutton):
  109.         self.pushbutton = pushbutton
  110.  
  111.  
  112.  
  113. class DefaultPushButton(QPushButton):
  114.     
  115.     def __init__(self, parent, name, group, option, choices, default, control, typ, job_option = False):
  116.         QPushButton.__init__(self, parent)
  117.         self.group = group
  118.         self.option = option
  119.         self.default = default
  120.         self.control = control
  121.         self.typ = typ
  122.         self.choices = choices
  123.         self.job_option = job_option
  124.         self.setObjectName(name)
  125.  
  126.  
  127.  
  128. class PageRangeRadioButton(QRadioButton):
  129.     
  130.     def __init__(self, parent, name, group, option, default):
  131.         QRadioButton.__init__(self, parent)
  132.         self.group = group
  133.         self.option = option
  134.         self.default = default
  135.         self.job_option = True
  136.         self.setObjectName(name)
  137.  
  138.     
  139.     def setRangeEdit(self, edit_control):
  140.         self.edit_control = edit_control
  141.  
  142.     
  143.     def setDefaultPushbutton(self, pushbutton):
  144.         self.pushbutton = pushbutton
  145.  
  146.  
  147.  
  148. class PrintSettingsToolbox(QToolBox):
  149.     
  150.     def __init__(self, parent, include_job_options = False):
  151.         QToolBox.__init__(self, parent)
  152.         self.include_job_options = include_job_options
  153.         self.plus_icon = QIcon(load_pixmap('plus', '16x16'))
  154.         self.minus_icon = QIcon(load_pixmap('minus', '16x16'))
  155.         self.last_item = 0
  156.         self.job_options = { }
  157.         self.job_storage_enable = False
  158.         self.connect(self, SIGNAL('currentChanged(int)'), self.PrintSettingsToolbox_currentChanged)
  159.  
  160.     
  161.     def getPrintCommands(self, file_list = None):
  162.         if file_list is None or not file_list:
  163.             return []
  164.         print_commands = []
  165.         
  166.         try:
  167.             copies = int(self.job_options['copies'])
  168.         except ValueError:
  169.             not file_list
  170.             not file_list
  171.             copies = 1
  172.         except:
  173.             not file_list
  174.  
  175.         if copies < 1:
  176.             copies = 1
  177.             log.warning('Copies < 1, setting to 1.')
  178.         elif copies > 99:
  179.             copies = 99
  180.             log.warning('Copies > 99, setting to 99.')
  181.         
  182.         page_range = self.job_options['pagerange']
  183.         
  184.         try:
  185.             x = utils.expand_range(page_range)
  186.         except ValueError:
  187.             log.error('Invalid page range: %s' % page_range)
  188.             return []
  189.  
  190.         all_pages = not page_range
  191.         page_set = self.job_options['pageset']
  192.         cups.resetOptions()
  193.         cups.openPPD(self.cur_printer)
  194.         current_options = dict(cups.getOptions())
  195.         cups.closePPD()
  196.         nup = int(current_options.get('number-up', 1))
  197.         psnup = utils.which('psnup')
  198.         for p, t, d, title, num_pages in file_list:
  199.             if nup > 1 and t == 'application/postscript':
  200.                 pass
  201.             alt_nup = psnup
  202.             if utils.which('lpr'):
  203.                 if alt_nup:
  204.                     cmd = ' '.join([
  205.                         'psnup',
  206.                         '-%d' % nup,
  207.                         ''.join([
  208.                             '"',
  209.                             p,
  210.                             '"']),
  211.                         '| lpr -P',
  212.                         self.cur_printer])
  213.                 else:
  214.                     cmd = ' '.join([
  215.                         'lpr -P',
  216.                         self.cur_printer])
  217.                 if copies > 1:
  218.                     cmd = ' '.join([
  219.                         cmd,
  220.                         '-#%d' % copies])
  221.                 
  222.             elif alt_nup:
  223.                 cmd = ' '.join([
  224.                     'psnup',
  225.                     '-%d' % nup,
  226.                     ''.join([
  227.                         '"',
  228.                         p,
  229.                         '"']),
  230.                     '| lp -c -d',
  231.                     self.cur_printer])
  232.             else:
  233.                 cmd = ' '.join([
  234.                     'lp -c -d',
  235.                     self.cur_printer])
  236.             if copies > 1:
  237.                 cmd = ' '.join([
  238.                     cmd,
  239.                     '-n%d' % copies])
  240.             
  241.             if not all_pages and page_range:
  242.                 cmd = ' '.join([
  243.                     cmd,
  244.                     '-o page-ranges=%s' % page_range])
  245.             
  246.             if page_set:
  247.                 cmd = ' '.join([
  248.                     cmd,
  249.                     '-o page-set=%s' % page_set])
  250.             
  251.             if self.job_storage_enable:
  252.                 if self.job_storage_mode != JOB_STORAGE_TYPE_OFF:
  253.                     if self.job_storage_mode == JOB_STORAGE_TYPE_PROOF_AND_HOLD:
  254.                         cmd = ' '.join([
  255.                             cmd,
  256.                             '-o HOLD=PROOF'])
  257.                     elif self.job_storage_mode == JOB_STORAGE_TYPE_PERSONAL:
  258.                         if self.job_storage_use_pin:
  259.                             cmd = ' '.join([
  260.                                 cmd,
  261.                                 '-o HOLD=ON'])
  262.                             cmd = ' '.join([
  263.                                 cmd,
  264.                                 '-o HOLDTYPE=PRIVATE'])
  265.                             cmd = ' '.join([
  266.                                 cmd,
  267.                                 '-o HOLDKEY=%s' % self.job_storage_pin.encode('ascii')])
  268.                         else:
  269.                             cmd = ' '.join([
  270.                                 cmd,
  271.                                 '-o HOLD=PROOF'])
  272.                             cmd = ' '.join([
  273.                                 cmd,
  274.                                 '-o HOLDTYPE=PRIVATE'])
  275.                     elif self.job_storage_mode == JOB_STORAGE_TYPE_QUICK_COPY:
  276.                         cmd = ' '.join([
  277.                             cmd,
  278.                             '-o HOLD=ON'])
  279.                         cmd = ' '.join([
  280.                             cmd,
  281.                             '-o HOLDTYPE=PUBLIC'])
  282.                     elif self.job_storage_mode == JOB_STORAGE_TYPE_STORE:
  283.                         if self.job_storage_use_pin:
  284.                             cmd = ' '.join([
  285.                                 cmd,
  286.                                 '-o HOLD=STORE'])
  287.                             cmd = ' '.join([
  288.                                 cmd,
  289.                                 '-o HOLDTYPE=PRIVATE'])
  290.                             cmd = ' '.join([
  291.                                 cmd,
  292.                                 '-o HOLDKEY=%s' % self.job_storage_pin.encode('ascii')])
  293.                         else:
  294.                             cmd = ' '.join([
  295.                                 cmd,
  296.                                 '-o HOLD=STORE'])
  297.                     
  298.                     cmd = ' '.join([
  299.                         cmd,
  300.                         '-o USERNAME=%s' % self.job_storage_username.encode('ascii').replace(' ', '_')])
  301.                     cmd = ' '.join([
  302.                         cmd,
  303.                         '-o JOBNAME=%s' % self.job_storage_jobname.encode('ascii').replace(' ', '_')])
  304.                     if self.job_storage_job_exist == 1:
  305.                         cmd = ' '.join([
  306.                             cmd,
  307.                             '-o DUPLICATEJOB=APPEND'])
  308.                     else:
  309.                         cmd = ' '.join([
  310.                             cmd,
  311.                             '-o DUPLICATEJOB=REPLACE'])
  312.                 else:
  313.                     cmd = ' '.join([
  314.                         cmd,
  315.                         '-o HOLD=OFF'])
  316.             
  317.             if not alt_nup:
  318.                 cmd = ''.join([
  319.                     cmd,
  320.                     ' "',
  321.                     p,
  322.                     '"'])
  323.             
  324.             print_commands.append(cmd)
  325.         
  326.         return print_commands
  327.  
  328.     
  329.     def PrintSettingsToolbox_currentChanged(self, i):
  330.         if i != -1:
  331.             self.setItemIcon(self.last_item, self.plus_icon)
  332.             self.setItemIcon(i, self.minus_icon)
  333.             self.last_item = i
  334.         
  335.  
  336.     
  337.     def updateUi(self, cur_device, cur_printer):
  338.         self.cur_device = cur_device
  339.         self.cur_printer = cur_printer
  340.         while self.count():
  341.             self.removeItem(0)
  342.         self.loading = True
  343.         cups.resetOptions()
  344.         cups.openPPD(self.cur_printer)
  345.         
  346.         try:
  347.             current_options = dict(cups.getOptions())
  348.             if self.include_job_options:
  349.                 self.beginControlGroup('job_options', self._PrintSettingsToolbox__tr('Job Options'))
  350.                 
  351.                 try:
  352.                     current = int(current_options.get('copies', '1'))
  353.                 except ValueError:
  354.                     current = 1
  355.  
  356.                 self.addControlRow('copies', self._PrintSettingsToolbox__tr('Number of copies'), cups.UI_SPINNER, current, (1, 99), 1, job_option = True)
  357.                 self.job_options['copies'] = current
  358.                 current = current_options.get('pagerange', '')
  359.                 self.addControlRow('pagerange', self._PrintSettingsToolbox__tr('Page Range'), cups.UI_PAGE_RANGE, current, None, None, job_option = True)
  360.                 self.job_options['pagerange'] = current
  361.                 current = current_options.get('pageset', '')
  362.                 self.addControlRow('pageset', self._PrintSettingsToolbox__tr('Page Set'), cups.PPD_UI_PICKONE, current, [
  363.                     ('all', self._PrintSettingsToolbox__tr('All pages')),
  364.                     ('even', self._PrintSettingsToolbox__tr('Even pages')),
  365.                     ('odd', self._PrintSettingsToolbox__tr('Odd pages'))], 'all', job_option = True)
  366.                 self.job_options['pageset'] = current
  367.                 self.endControlGroup()
  368.             
  369.             if not self.cur_device.device_type == DEVICE_TYPE_FAX:
  370.                 self.beginControlGroup('basic', self._PrintSettingsToolbox__tr('Basic'))
  371.                 current = current_options.get('orientation-requested', '3')
  372.                 self.addControlRow('orientation-requested', self._PrintSettingsToolbox__tr('Page Orientation'), cups.PPD_UI_PICKONE, current, [
  373.                     ('3', self._PrintSettingsToolbox__tr('Portrait')),
  374.                     ('4', self._PrintSettingsToolbox__tr('Landscape')),
  375.                     ('5', self._PrintSettingsToolbox__tr('Reverse landscape')),
  376.                     ('6', self._PrintSettingsToolbox__tr('Reverse portrait'))], '3')
  377.                 log.debug('Option: orientation-requested')
  378.                 log.debug('Current value: %s' % current)
  379.                 duplexer = self.cur_device.dq.get('duplexer', 0)
  380.                 log.debug('Duplexer = %d' % duplexer)
  381.                 if duplexer:
  382.                     current = current_options.get('sides', 'one-sided')
  383.                     self.addControlRow('sides', self._PrintSettingsToolbox__tr('Duplex (Print on both sides of the page)'), cups.PPD_UI_PICKONE, current, [
  384.                         ('one-sided', self._PrintSettingsToolbox__tr('Single sided')),
  385.                         ('two-sided-long-edge', self._PrintSettingsToolbox__tr('Two sided (long edge)')),
  386.                         ('two-sided-short-edge', self._PrintSettingsToolbox__tr('Two sided (short edge)'))], 'one-sided')
  387.                     log.debug('Option: sides')
  388.                     log.debug('Current value: %s' % current)
  389.                 
  390.                 current = current_options.get('outputorder', 'normal')
  391.                 self.addControlRow('outputorder', self._PrintSettingsToolbox__tr('Output Order (Print last page first)'), cups.PPD_UI_PICKONE, current, [
  392.                     ('normal', self._PrintSettingsToolbox__tr('Normal (Print first page first)')),
  393.                     ('reverse', self._PrintSettingsToolbox__tr('Reversed (Print last page first)'))], 'normal')
  394.                 log.debug('Option: outputorder')
  395.                 log.debug('Current value: %s' % current)
  396.                 current = utils.to_bool(current_options.get('Collate', '0'))
  397.                 self.addControlRow('Collate', self._PrintSettingsToolbox__tr('Collate (Group together multiple copies)'), cups.PPD_UI_BOOLEAN, current, [], 0)
  398.                 log.debug('Option: Collate')
  399.                 log.debug('Current value: %s' % current)
  400.                 self.endControlGroup()
  401.             
  402.             groups = cups.getGroupList()
  403.             for g in groups:
  404.                 if 'jobretention' in g.lower():
  405.                     log.debug('HPJobRetention skipped.')
  406.                     continue
  407.                 
  408.                 
  409.                 try:
  410.                     (text, num_subgroups) = cups.getGroup(g)
  411.                 except TypeError:
  412.                     log.warn('Group %s returned None' % g)
  413.                     continue
  414.  
  415.                 read_only = 'install' in g.lower()
  416.                 
  417.                 try:
  418.                     text = text.decode('utf-8')
  419.                 except UnicodeDecodeError:
  420.                     pass
  421.  
  422.                 if g.lower() == 'printoutmode':
  423.                     text = self._PrintSettingsToolbox__tr("Quality (also see 'Printout Mode' under 'General')")
  424.                 
  425.                 self.beginControlGroup(g, QString(text))
  426.                 log.debug('  Text: %s' % unicode(text))
  427.                 log.debug('Num subgroups: %d' % num_subgroups)
  428.                 options = cups.getOptionList(g)
  429.                 for o in options:
  430.                     log.debug('  Option: %s' % repr(o))
  431.                     if 'pageregion' in o.lower():
  432.                         log.debug('Page Region skipped.')
  433.                         continue
  434.                     
  435.                     
  436.                     try:
  437.                         (option_text, defchoice, conflicted, ui) = cups.getOption(g, o)
  438.                     except TypeError:
  439.                         log.warn('Option %s in group %s returned None' % (o, g))
  440.                         continue
  441.  
  442.                     
  443.                     try:
  444.                         option_text = option_text.decode('utf-8')
  445.                     except UnicodeDecodeError:
  446.                         pass
  447.  
  448.                     if o.lower() == 'quality':
  449.                         option_text = self._PrintSettingsToolbox__tr('Quality')
  450.                     
  451.                     log.debug('    Text: %s' % repr(option_text))
  452.                     log.debug('    Defchoice: %s' % repr(defchoice))
  453.                     choices = cups.getChoiceList(g, o)
  454.                     value = None
  455.                     choice_data = []
  456.                     for c in choices:
  457.                         log.debug('    Choice: %s' % repr(c))
  458.                         if 'pagesize' in o.lower() and 'custom' in c.lower():
  459.                             log.debug('Skipped.')
  460.                             continue
  461.                         
  462.                         (choice_text, marked) = cups.getChoice(g, o, c)
  463.                         
  464.                         try:
  465.                             choice_text = choice_text.decode('utf-8')
  466.                         except UnicodeDecodeError:
  467.                             pass
  468.  
  469.                         log.debug('      Text: %s' % repr(choice_text))
  470.                         if marked:
  471.                             value = c
  472.                         
  473.                         choice_data.append((c, choice_text))
  474.                     
  475.                     self.addControlRow(o, option_text, ui, value, choice_data, defchoice, read_only)
  476.                 
  477.                 self.endControlGroup()
  478.             
  479.             self.beginControlGroup('nup', self._PrintSettingsToolbox__tr('N-Up (Multiple document pages per printed page)'))
  480.             current = current_options.get('number-up', '1')
  481.             self.addControlRow('number-up', self._PrintSettingsToolbox__tr('Pages per Sheet'), cups.PPD_UI_PICKONE, current, [
  482.                 ('1', self._PrintSettingsToolbox__tr('1 page per sheet')),
  483.                 ('2', self._PrintSettingsToolbox__tr('2 pages per sheet')),
  484.                 ('4', self._PrintSettingsToolbox__tr('4 pages per sheet'))], '1')
  485.             log.debug('  Option: number-up')
  486.             log.debug('  Current value: %s' % current)
  487.             current = current_options.get('number-up-layout', 'lrtb')
  488.             self.addControlRow('number-up-layout', self._PrintSettingsToolbox__tr('Layout'), cups.PPD_UI_PICKONE, current, [
  489.                 ('btlr', self._PrintSettingsToolbox__tr('Bottom to top, left to right')),
  490.                 ('btrl', self._PrintSettingsToolbox__tr('Bottom to top, right to left')),
  491.                 ('lrbt', self._PrintSettingsToolbox__tr('Left to right, bottom to top')),
  492.                 ('lrtb', self._PrintSettingsToolbox__tr('Left to right, top to bottom')),
  493.                 ('rlbt', self._PrintSettingsToolbox__tr('Right to left, bottom to top')),
  494.                 ('rltb', self._PrintSettingsToolbox__tr('Right to left, top to bottom')),
  495.                 ('tblr', self._PrintSettingsToolbox__tr('Top to bottom, left to right')),
  496.                 ('tbrl', self._PrintSettingsToolbox__tr('Top to bottom, right to left'))], 'lrtb')
  497.             log.debug('  Option: number-up-layout')
  498.             log.debug('  Current value: %s' % current)
  499.             current = current_options.get('page-border', 'none')
  500.             self.addControlRow('page-border', self._PrintSettingsToolbox__tr('Printed Border Around Each Page'), cups.PPD_UI_PICKONE, current, [
  501.                 ('double', self._PrintSettingsToolbox__tr('Two thin borders')),
  502.                 ('double-thick', self._PrintSettingsToolbox__tr('Two thick borders')),
  503.                 ('none', self._PrintSettingsToolbox__tr('No border')),
  504.                 ('single', self._PrintSettingsToolbox__tr('One thin border')),
  505.                 ('single-thick', self._PrintSettingsToolbox__tr('One thick border'))], 'none')
  506.             log.debug('  Option: page-border')
  507.             log.debug('  Current value: %s' % current)
  508.             self.endControlGroup()
  509.             if not self.cur_device.device_type == DEVICE_TYPE_FAX:
  510.                 self.beginControlGroup('adjustment', self._PrintSettingsToolbox__tr('Printout Appearance'))
  511.                 current = int(current_options.get('brightness', 100))
  512.                 log.debug('  Option: brightness')
  513.                 log.debug('  Current value: %s' % current)
  514.                 self.addControlRow('brightness', self._PrintSettingsToolbox__tr('Brightness'), cups.UI_SPINNER, current, (0, 200), 100, suffix = ' %')
  515.                 current = int(current_options.get('gamma', 1000))
  516.                 log.debug('  Option: gamma')
  517.                 log.debug('  Current value: %s' % current)
  518.                 self.addControlRow('gamma', self._PrintSettingsToolbox__tr('Gamma'), cups.UI_SPINNER, current, (1, 10000), 1000)
  519.                 self.endControlGroup()
  520.             
  521.             self.beginControlGroup('image', self._PrintSettingsToolbox__tr('Image Printing'))
  522.             current = utils.to_bool(current_options.get('fitplot', 'false'))
  523.             self.addControlRow('fitplot', self._PrintSettingsToolbox__tr('Fit to Page'), cups.PPD_UI_BOOLEAN, current, [], 0)
  524.             current = current_options.get('position', 'center')
  525.             self.addControlRow('position', self._PrintSettingsToolbox__tr('Position on Page'), cups.PPD_UI_PICKONE, current, [
  526.                 ('center', self._PrintSettingsToolbox__tr('Centered')),
  527.                 ('top', self._PrintSettingsToolbox__tr('Top')),
  528.                 ('left', self._PrintSettingsToolbox__tr('Left')),
  529.                 ('right', self._PrintSettingsToolbox__tr('Right')),
  530.                 ('top-left', self._PrintSettingsToolbox__tr('Top left')),
  531.                 ('top-right', self._PrintSettingsToolbox__tr('Top right')),
  532.                 ('bottom', self._PrintSettingsToolbox__tr('Bottom')),
  533.                 ('bottom-left', self._PrintSettingsToolbox__tr('Bottom left')),
  534.                 ('bottom-right', self._PrintSettingsToolbox__tr('Bottom right'))], 'center')
  535.             log.debug('  Option: position')
  536.             log.debug('  Current value: %s' % current)
  537.             if not self.cur_device.device_type == DEVICE_TYPE_FAX:
  538.                 current = int(current_options.get('saturation', 100))
  539.                 log.debug('  Option: saturation')
  540.                 log.debug('  Current value: %s' % current)
  541.                 self.addControlRow('saturation', self._PrintSettingsToolbox__tr('Saturation'), cups.UI_SPINNER, current, (0, 200), 100, suffix = ' %')
  542.                 current = int(current_options.get('hue', 0))
  543.                 log.debug('  Option: hue')
  544.                 log.debug('  Current value: %s' % current)
  545.                 self.addControlRow('hue', self._PrintSettingsToolbox__tr('Hue (color shift/rotation)'), cups.UI_SPINNER, current, (-100, 100), 0)
  546.             
  547.             current = int(current_options.get('natural-scaling', 100))
  548.             log.debug('  Option: natural-scaling')
  549.             log.debug('  Current value: %s' % current)
  550.             self.addControlRow('natural-scaling', self._PrintSettingsToolbox__tr('"Natural" Scaling (relative to image)'), cups.UI_SPINNER, current, (1, 800), 100, suffix = ' %')
  551.             current = int(current_options.get('scaling', 100))
  552.             log.debug('  Option: scaling')
  553.             log.debug('  Current value: %s' % current)
  554.             self.addControlRow('scaling', self._PrintSettingsToolbox__tr('Scaling (relative to page)'), cups.UI_SPINNER, current, (1, 800), 100, suffix = ' %')
  555.             self.endControlGroup()
  556.             self.beginControlGroup('misc', self._PrintSettingsToolbox__tr('Miscellaneous'))
  557.             log.debug('Group: Misc')
  558.             current = utils.to_bool(current_options.get('prettyprint', '0'))
  559.             self.addControlRow('prettyprint', self._PrintSettingsToolbox__tr('"Pretty Print" Text Documents (Add headers and formatting)'), cups.PPD_UI_BOOLEAN, current, [], 0)
  560.             log.debug('  Option: prettyprint')
  561.             log.debug('  Current value: %s' % current)
  562.             if not self.cur_device.device_type == DEVICE_TYPE_FAX:
  563.                 current = current_options.get('job-sheets', 'none').split(',')
  564.                 
  565.                 try:
  566.                     start = current[0]
  567.                 except IndexError:
  568.                     start = 'none'
  569.  
  570.                 
  571.                 try:
  572.                     end = current[1]
  573.                 except IndexError:
  574.                     end = 'none'
  575.  
  576.                 self.addControlRow('job-sheets', self._PrintSettingsToolbox__tr('Banner Pages'), cups.UI_BANNER_JOB_SHEETS, (start, end), [
  577.                     ('none', self._PrintSettingsToolbox__tr('No banner page')),
  578.                     ('classified', self._PrintSettingsToolbox__tr('Classified')),
  579.                     ('confidential', self._PrintSettingsToolbox__tr('Confidential')),
  580.                     ('secret', self._PrintSettingsToolbox__tr('Secret')),
  581.                     ('standard', self._PrintSettingsToolbox__tr('Standard')),
  582.                     ('topsecret', self._PrintSettingsToolbox__tr('Top secret')),
  583.                     ('unclassified', self._PrintSettingsToolbox__tr('Unclassified'))], ('none', 'none'))
  584.                 log.debug('  Option: job-sheets')
  585.                 log.debug('  Current value: %s,%s' % (start, end))
  586.             
  587.             current = utils.to_bool(current_options.get('mirror', '0'))
  588.             self.addControlRow('mirror', self._PrintSettingsToolbox__tr('Mirror Printing'), cups.PPD_UI_BOOLEAN, current, [], 0)
  589.             log.debug('  Option: mirror')
  590.             log.debug('  Current value: %s' % current)
  591.             self.endControlGroup()
  592.             self.job_storage_enable = self.cur_device.mq.get('job-storage', JOB_STORAGE_DISABLE) == JOB_STORAGE_ENABLE
  593.             if self.job_storage_enable:
  594.                 self.job_storage_pin = unicode(current_options.get('HOLDKEY', '0000')[:4])
  595.                 self.job_storage_username = unicode(current_options.get('USERNAME', prop.username)[:16])
  596.                 self.job_storage_jobname = unicode(current_options.get('JOBNAME', u'Untitled')[:16])
  597.                 hold = unicode(current_options.get('HOLD', u'OFF'))
  598.                 holdtype = unicode(current_options.get('HOLDTYPE', u'PUBLIC'))
  599.                 self.job_storage_use_pin = False
  600.                 duplicate = unicode(current_options.get('DUPLICATEJOB', u'REPLACE'))
  601.                 self.job_storage_auto_username = True
  602.                 self.job_storage_auto_jobname = True
  603.                 self.job_storage_mode = JOB_STORAGE_TYPE_OFF
  604.                 if hold == 'OFF':
  605.                     self.job_storage_mode = JOB_STORAGE_TYPE_OFF
  606.                 elif hold == 'ON':
  607.                     if holdtype == u'PUBLIC':
  608.                         self.job_storage_mode = JOB_STORAGE_TYPE_QUICK_COPY
  609.                     else:
  610.                         self.job_storage_mode = JOB_STORAGE_TYPE_PERSONAL
  611.                         self.job_storage_use_pin = True
  612.                 elif hold == u'PROOF':
  613.                     if holdtype == u'PUBLIC':
  614.                         self.job_storage_mode = JOB_STORAGE_TYPE_PROOF_AND_HOLD
  615.                     else:
  616.                         self.job_storage_mode = JOB_STORAGE_TYPE_PERSONAL
  617.                         self.job_storage_use_pin = True
  618.                 elif hold == u'STORE':
  619.                     self.job_storage_mode = JOB_STORAGE_TYPE_STORE
  620.                     self.job_storage_use_pin = holdtype == u'PRIVATE'
  621.                 
  622.                 if duplicate == u'REPLACE':
  623.                     self.job_storage_job_exist = JOB_STORAGE_EXISTING_JOB_REPLACE
  624.                 else:
  625.                     self.job_storage_job_exist = JOB_STORAGE_EXISTING_JOB_APPEND_1_99
  626.                 self.beginControlGroup('jobstorage', self._PrintSettingsToolbox__tr('Job Storage and Secure Printing'))
  627.                 self.addControlRow('job-storage-mode', self._PrintSettingsToolbox__tr('Mode'), cups.UI_JOB_STORAGE_MODE, None, None, None)
  628.                 self.addControlRow('job-storage-pin', self._PrintSettingsToolbox__tr('Make job private (use PIN to print)'), cups.UI_JOB_STORAGE_PIN, None, None, None)
  629.                 self.addControlRow('job-storage-username', self._PrintSettingsToolbox__tr('User name (for job identification)'), cups.UI_JOB_STORAGE_USERNAME, None, None, None)
  630.                 self.addControlRow('job-storage-id', self._PrintSettingsToolbox__tr('Job name/ID (for job identification)'), cups.UI_JOB_STORAGE_ID, None, None, None)
  631.                 self.addControlRow('job-storage-id-exists', self._PrintSettingsToolbox__tr('If job name/ID already exists...'), cups.UI_JOB_STORAGE_ID_EXISTS, None, None, None)
  632.                 self.endControlGroup()
  633.                 self.updateJobStorageControls()
  634.         finally:
  635.             cups.closePPD()
  636.             self.loading = False
  637.  
  638.  
  639.     
  640.     def beginControlGroup(self, group, text):
  641.         log.debug('BeginGroup: %s' % group)
  642.         self.row = 0
  643.         self.widget = QWidget()
  644.         self.gridlayout = QGridLayout(self.widget)
  645.         self.group = group
  646.         self.text = text
  647.  
  648.     
  649.     def endControlGroup(self):
  650.         log.debug('EndGroup: %s' % self.group)
  651.         spacer = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding)
  652.         self.row += 1
  653.         self.gridlayout.addItem(spacer, self.row, 0, 1, 1)
  654.         i = self.addItem(self.widget, self.text)
  655.         if i:
  656.             self.setItemIcon(i, self.plus_icon)
  657.         else:
  658.             self.setItemIcon(i, self.minus_icon)
  659.         (self.widget, self.gridlayout) = (None, None)
  660.  
  661.     
  662.     def addControlRow(self, option, text, typ, value, choices, default, read_only = False, suffix = '', job_option = False):
  663.         if typ == cups.PPD_UI_BOOLEAN:
  664.             HBoxLayout = QHBoxLayout()
  665.             HBoxLayout.setObjectName('HBoxLayout')
  666.             OptionLabel = QLabel(self.widget)
  667.             OptionLabel.setObjectName('OptionLabel')
  668.             HBoxLayout.addWidget(OptionLabel)
  669.             SpacerItem = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  670.             HBoxLayout.addItem(SpacerItem)
  671.             GroupBox = QFrame(self.widget)
  672.             gridlayout1 = QGridLayout(GroupBox)
  673.             OnRadioButton = OptionRadioButton(GroupBox, 'OnRadioButton', self.group, option, default, job_option)
  674.             gridlayout1.addWidget(OnRadioButton, 0, 0, 1, 1)
  675.             OffRadioButton = OptionRadioButton(GroupBox, 'OffRadioButton', self.group, option, default, job_option)
  676.             gridlayout1.addWidget(OffRadioButton, 0, 1, 1, 1)
  677.             HBoxLayout.addWidget(GroupBox)
  678.             DefaultButton = DefaultPushButton(self.widget, 'defaultPushButton', self.group, option, choices, default, (OnRadioButton, OffRadioButton), typ, job_option)
  679.             OnRadioButton.setDefaultPushbutton(DefaultButton)
  680.             OffRadioButton.setDefaultPushbutton(DefaultButton)
  681.             HBoxLayout.addWidget(DefaultButton)
  682.             self.gridlayout.addLayout(HBoxLayout, self.row, 0, 1, 1)
  683.             OptionLabel.setText(text)
  684.             OnRadioButton.setText(self._PrintSettingsToolbox__tr('On'))
  685.             OffRadioButton.setText(self._PrintSettingsToolbox__tr('Off'))
  686.             DefaultButton.setText('Default')
  687.             if value == default:
  688.                 DefaultButton.setEnabled(False)
  689.             
  690.             self.connect(DefaultButton, SIGNAL('clicked()'), self.DefaultButton_clicked)
  691.             if value:
  692.                 OnRadioButton.setChecked(True)
  693.             else:
  694.                 OffRadioButton.setChecked(True)
  695.             self.connect(OnRadioButton, SIGNAL('toggled(bool)'), self.BoolRadioButtons_clicked)
  696.             if read_only:
  697.                 OnRadioButton.setEnabled(False)
  698.                 OffRadioButton.setEnabled(False)
  699.                 DefaultButton.setEnabled(False)
  700.             
  701.         elif typ == cups.PPD_UI_PICKONE:
  702.             HBoxLayout = QHBoxLayout()
  703.             HBoxLayout.setObjectName('HBoxLayout')
  704.             OptionLabel = QLabel(self.widget)
  705.             OptionLabel.setObjectName('OptionLabel')
  706.             HBoxLayout.addWidget(OptionLabel)
  707.             SpacerItem = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  708.             HBoxLayout.addItem(SpacerItem)
  709.             ComboBox = OptionComboBox(0, self.widget, 'ComboBox', self.group, option, choices, default, typ, None, job_option)
  710.             HBoxLayout.addWidget(ComboBox)
  711.             DefaultButton = DefaultPushButton(self.widget, 'DefaultButton', self.group, option, choices, default, ComboBox, typ, job_option)
  712.             ComboBox.setDefaultPushbutton(DefaultButton)
  713.             HBoxLayout.addWidget(DefaultButton)
  714.             self.gridlayout.addLayout(HBoxLayout, self.row, 0, 1, 1)
  715.             OptionLabel.setText(text)
  716.             DefaultButton.setText('Default')
  717.             (i, x, y) = (0, None, None)
  718.             for c, t in choices:
  719.                 d = c.lower()
  720.                 if value is not None and d == value.lower():
  721.                     x = i
  722.                 
  723.                 if d == default.lower():
  724.                     y = t
  725.                 
  726.                 ComboBox.insertItem(i, t)
  727.                 i += 1
  728.             
  729.             if x is not None:
  730.                 ComboBox.setCurrentIndex(x)
  731.             else:
  732.                 ComboBox.setCurrentIndex(0)
  733.             if value is not None and value.lower() == default.lower():
  734.                 DefaultButton.setEnabled(False)
  735.             
  736.             self.connect(DefaultButton, SIGNAL('clicked()'), self.DefaultButton_clicked)
  737.             self.connect(ComboBox, SIGNAL('highlighted(const QString &)'), self.ComboBox_highlighted)
  738.             control = ComboBox
  739.         elif typ == cups.UI_SPINNER:
  740.             HBoxLayout = QHBoxLayout()
  741.             HBoxLayout.setObjectName('HBoxLayout')
  742.             OptionLabel = QLabel(self.widget)
  743.             OptionLabel.setObjectName('OptionLabel')
  744.             HBoxLayout.addWidget(OptionLabel)
  745.             SpacerItem = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  746.             HBoxLayout.addItem(SpacerItem)
  747.             SpinBox = OptionSpinBox(self.widget, 'SpinBox', self.group, option, default, job_option)
  748.             HBoxLayout.addWidget(SpinBox)
  749.             DefaultButton = DefaultPushButton(self.widget, 'DefaultButton', self.group, option, choices, default, SpinBox, typ, job_option)
  750.             SpinBox.setDefaultPushbutton(DefaultButton)
  751.             HBoxLayout.addWidget(DefaultButton)
  752.             self.gridlayout.addLayout(HBoxLayout, self.row, 0, 1, 1)
  753.             (min, max) = choices
  754.             SpinBox.setMinimum(min)
  755.             SpinBox.setMaximum(max)
  756.             SpinBox.setValue(value)
  757.             if suffix:
  758.                 SpinBox.setSuffix(suffix)
  759.             
  760.             OptionLabel.setText(text)
  761.             DefaultButton.setText('Default')
  762.             self.connect(SpinBox, SIGNAL('valueChanged(int)'), self.SpinBox_valueChanged)
  763.             self.connect(DefaultButton, SIGNAL('clicked()'), self.DefaultButton_clicked)
  764.             DefaultButton.setEnabled(not (value == default))
  765.             if read_only:
  766.                 SpinBox.setEnabled(False)
  767.                 DefaultButton.setEnabled(False)
  768.             
  769.         elif typ == cups.UI_BANNER_JOB_SHEETS:
  770.             HBoxLayout = QHBoxLayout()
  771.             HBoxLayout.setObjectName('HBoxLayout')
  772.             OptionLabel = QLabel(self.widget)
  773.             OptionLabel.setObjectName('OptionLabel')
  774.             HBoxLayout.addWidget(OptionLabel)
  775.             SpacerItem = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  776.             HBoxLayout.addItem(SpacerItem)
  777.             StartLabel = QLabel(self.widget)
  778.             HBoxLayout.addWidget(StartLabel)
  779.             StartComboBox = OptionComboBox(0, self.widget, 'StartComboBox', self.group, 'start', choices, default, typ)
  780.             HBoxLayout.addWidget(StartComboBox)
  781.             EndLabel = QLabel(self.widget)
  782.             HBoxLayout.addWidget(EndLabel)
  783.             EndComboBox = OptionComboBox(0, self.widget, 'EndComboBox', self.group, 'end', choices, default, typ, StartComboBox)
  784.             HBoxLayout.addWidget(EndComboBox)
  785.             StartComboBox.setOther(EndComboBox)
  786.             DefaultButton = DefaultPushButton(self.widget, 'DefaultButton', self.group, option, choices, default, (StartComboBox, EndComboBox), typ, job_option)
  787.             HBoxLayout.addWidget(DefaultButton)
  788.             self.gridlayout.addLayout(HBoxLayout, self.row, 0, 1, 1)
  789.             StartComboBox.setDefaultPushbutton(DefaultButton)
  790.             EndComboBox.setDefaultPushbutton(DefaultButton)
  791.             OptionLabel.setText(text)
  792.             DefaultButton.setText('Default')
  793.             StartLabel.setText(self._PrintSettingsToolbox__tr('Start:'))
  794.             EndLabel.setText(self._PrintSettingsToolbox__tr('End:'))
  795.             (s, e, y, z) = (None, None, None, None)
  796.             for c, t in choices:
  797.                 d = c.lower()
  798.                 if value is not None:
  799.                     if d == value[0].lower():
  800.                         s = t
  801.                     
  802.                     if d == value[1].lower():
  803.                         e = t
  804.                     
  805.                 
  806.                 if d == default[0].lower():
  807.                     y = t
  808.                 
  809.                 if d == default[1].lower():
  810.                     z = t
  811.                 
  812.                 StartComboBox.insertItem(0, t)
  813.                 EndComboBox.insertItem(0, t)
  814.             
  815.             if s is not None:
  816.                 StartComboBox.setCurrentIndex(StartComboBox.findText(s))
  817.             
  818.             if e is not None:
  819.                 EndComboBox.setCurrentIndex(EndComboBox.findText(e))
  820.             
  821.             if value is not None and value[0].lower() == default[0].lower() and value[1].lower() == default[1].lower():
  822.                 DefaultButton.setEnabled(False)
  823.             
  824.             self.connect(StartComboBox, SIGNAL('activated(const QString&)'), self.BannerComboBox_activated)
  825.             self.connect(EndComboBox, SIGNAL('activated(const QString&)'), self.BannerComboBox_activated)
  826.             self.connect(DefaultButton, SIGNAL('clicked()'), self.DefaultButton_clicked)
  827.         elif typ == cups.PPD_UI_PICKMANY:
  828.             log.error('Unrecognized type: pickmany')
  829.         elif typ == cups.UI_UNITS_SPINNER:
  830.             log.error('Unrecognized type: units spinner')
  831.         elif typ == cups.UI_PAGE_RANGE:
  832.             HBoxLayout = QHBoxLayout()
  833.             HBoxLayout.setObjectName('HBoxLayout')
  834.             OptionLabel = QLabel(self.widget)
  835.             OptionLabel.setObjectName('OptionLabel')
  836.             HBoxLayout.addWidget(OptionLabel)
  837.             SpacerItem = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  838.             HBoxLayout.addItem(SpacerItem)
  839.             GroupBox = QFrame(self.widget)
  840.             gridlayout1 = QGridLayout(GroupBox)
  841.             AllRadioButton = PageRangeRadioButton(GroupBox, 'AllRadioButton', self.group, option, default)
  842.             gridlayout1.addWidget(AllRadioButton, 0, 0, 1, 1)
  843.             RangeRadioButton = PageRangeRadioButton(GroupBox, 'RangeRadioButton', self.group, option, default)
  844.             gridlayout1.addWidget(RangeRadioButton, 0, 1, 1, 1)
  845.             HBoxLayout.addWidget(GroupBox)
  846.             PageRangeEdit = QLineEdit(self.widget)
  847.             HBoxLayout.addWidget(PageRangeEdit)
  848.             PageRangeEdit.setValidator(RangeValidator(PageRangeEdit))
  849.             AllRadioButton.setRangeEdit(PageRangeEdit)
  850.             RangeRadioButton.setRangeEdit(PageRangeEdit)
  851.             DefaultButton = DefaultPushButton(self.widget, 'defaultPushButton', self.group, option, choices, default, (AllRadioButton, RangeRadioButton, PageRangeEdit), typ, job_option)
  852.             AllRadioButton.setDefaultPushbutton(DefaultButton)
  853.             RangeRadioButton.setDefaultPushbutton(DefaultButton)
  854.             HBoxLayout.addWidget(DefaultButton)
  855.             self.gridlayout.addLayout(HBoxLayout, self.row, 0, 1, 1)
  856.             OptionLabel.setText(text)
  857.             AllRadioButton.setText(self._PrintSettingsToolbox__tr('All pages'))
  858.             RangeRadioButton.setText(self._PrintSettingsToolbox__tr('Page Range:'))
  859.             DefaultButton.setText('Default')
  860.             DefaultButton.setEnabled(False)
  861.             AllRadioButton.setChecked(True)
  862.             PageRangeEdit.setEnabled(False)
  863.             self.connect(AllRadioButton, SIGNAL('toggled(bool)'), self.PageRangeAllRadio_toggled)
  864.             self.connect(RangeRadioButton, SIGNAL('toggled(bool)'), self.PageRangeRangeRadio_toggled)
  865.             self.connect(DefaultButton, SIGNAL('clicked()'), self.DefaultButton_clicked)
  866.             self.connect(PageRangeEdit, SIGNAL('textChanged(const QString &)'), self.PageRangeEdit_textChanged)
  867.             self.connect(PageRangeEdit, SIGNAL('editingFinished()'), self.PageRangeEdit_editingFinished)
  868.         elif typ == cups.UI_JOB_STORAGE_MODE:
  869.             HBoxLayout = QHBoxLayout()
  870.             HBoxLayout.setObjectName('HBoxLayout')
  871.             OptionLabel = QLabel(self.widget)
  872.             OptionLabel.setObjectName('OptionLabel')
  873.             HBoxLayout.addWidget(OptionLabel)
  874.             SpacerItem = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  875.             HBoxLayout.addItem(SpacerItem)
  876.             self.JobStorageModeComboBox = QComboBox(self.widget)
  877.             HBoxLayout.addWidget(self.JobStorageModeComboBox)
  878.             self.JobStorageModeDefaultButton = QPushButton(self.widget)
  879.             HBoxLayout.addWidget(self.JobStorageModeDefaultButton)
  880.             self.gridlayout.addLayout(HBoxLayout, self.row, 0, 1, 1)
  881.             OptionLabel.setText(text)
  882.             self.JobStorageModeDefaultButton.setText(self._PrintSettingsToolbox__tr('Default'))
  883.             self.JobStorageModeComboBox.addItem(self._PrintSettingsToolbox__tr('Off/Disabled'), QVariant(JOB_STORAGE_TYPE_OFF))
  884.             self.JobStorageModeComboBox.addItem(self._PrintSettingsToolbox__tr('Proof and Hold'), QVariant(JOB_STORAGE_TYPE_PROOF_AND_HOLD))
  885.             self.JobStorageModeComboBox.addItem(self._PrintSettingsToolbox__tr('Personal/Private Job'), QVariant(JOB_STORAGE_TYPE_PERSONAL))
  886.             self.JobStorageModeComboBox.addItem(self._PrintSettingsToolbox__tr('Quick Copy'), QVariant(JOB_STORAGE_TYPE_QUICK_COPY))
  887.             self.JobStorageModeComboBox.addItem(self._PrintSettingsToolbox__tr('Stored Job'), QVariant(JOB_STORAGE_TYPE_STORE))
  888.             self.connect(self.JobStorageModeComboBox, SIGNAL('activated(int)'), self.JobStorageModeComboBox_activated)
  889.             self.connect(self.JobStorageModeDefaultButton, SIGNAL('clicked()'), self.JobStorageModeDefaultButton_clicked)
  890.         elif typ == cups.UI_JOB_STORAGE_PIN:
  891.             HBoxLayout = QHBoxLayout()
  892.             HBoxLayout.setObjectName('HBoxLayout')
  893.             OptionLabel = QLabel(self.widget)
  894.             OptionLabel.setObjectName('OptionLabel')
  895.             HBoxLayout.addWidget(OptionLabel)
  896.             SpacerItem = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  897.             HBoxLayout.addItem(SpacerItem)
  898.             self.JobStoragePinGroupBox = QFrame(self.widget)
  899.             gridlayout1 = QGridLayout(self.JobStoragePinGroupBox)
  900.             self.JobStoragePinOffRadioButton = QRadioButton(self.JobStoragePinGroupBox)
  901.             gridlayout1.addWidget(self.JobStoragePinOffRadioButton, 0, 0, 1, 1)
  902.             self.JobStoragePinPrivateRadioButton = QRadioButton(self.JobStoragePinGroupBox)
  903.             gridlayout1.addWidget(self.JobStoragePinPrivateRadioButton, 0, 1, 1, 1)
  904.             self.JobStoragePinEdit = QLineEdit(self.JobStoragePinGroupBox)
  905.             self.JobStoragePinEdit.setMaxLength(4)
  906.             self.JobStoragePinEdit.setValidator(PinValidator(self.JobStoragePinEdit))
  907.             gridlayout1.addWidget(self.JobStoragePinEdit, 0, 2, 1, 1)
  908.             HBoxLayout.addWidget(self.JobStoragePinGroupBox)
  909.             self.JobStoragePinDefaultButton = QPushButton(self.widget)
  910.             HBoxLayout.addWidget(self.JobStoragePinDefaultButton)
  911.             self.JobStoragePinOffRadioButton.setText(self._PrintSettingsToolbox__tr('Public/Off'))
  912.             self.JobStoragePinPrivateRadioButton.setText(self._PrintSettingsToolbox__tr('Private/Use PIN:'))
  913.             self.gridlayout.addLayout(HBoxLayout, self.row, 0, 1, 1)
  914.             OptionLabel.setText(text)
  915.             self.JobStoragePinDefaultButton.setText(self._PrintSettingsToolbox__tr('Default'))
  916.             self.connect(self.JobStoragePinOffRadioButton, SIGNAL('toggled(bool)'), self.JobStoragePinOffRadioButton_toggled)
  917.             self.connect(self.JobStoragePinPrivateRadioButton, SIGNAL('toggled(bool)'), self.JobStoragePinPrivateRadioButton_toggled)
  918.             self.connect(self.JobStoragePinDefaultButton, SIGNAL('clicked()'), self.JobStoragePinDefaultButton_clicked)
  919.             self.connect(self.JobStoragePinEdit, SIGNAL('textEdited(const QString &)'), self.JobStoragePinEdit_textEdited)
  920.         elif typ == cups.UI_JOB_STORAGE_USERNAME:
  921.             HBoxLayout = QHBoxLayout()
  922.             HBoxLayout.setObjectName('HBoxLayout')
  923.             OptionLabel = QLabel(self.widget)
  924.             OptionLabel.setObjectName('OptionLabel')
  925.             HBoxLayout.addWidget(OptionLabel)
  926.             OptionLabel.setText(text)
  927.             SpacerItem = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  928.             HBoxLayout.addItem(SpacerItem)
  929.             self.JobStorageUsernameGroupBox = QFrame(self.widget)
  930.             gridlayout1 = QGridLayout(self.JobStorageUsernameGroupBox)
  931.             self.JobStorageUsernameAutoRadioButton = QRadioButton(self.JobStorageUsernameGroupBox)
  932.             gridlayout1.addWidget(self.JobStorageUsernameAutoRadioButton, 0, 0, 1, 1)
  933.             self.JobStorageUsernameCustomRadioButton = QRadioButton(self.JobStorageUsernameGroupBox)
  934.             gridlayout1.addWidget(self.JobStorageUsernameCustomRadioButton, 0, 1, 1, 1)
  935.             self.JobStorageUsernameEdit = QLineEdit(self.JobStorageUsernameGroupBox)
  936.             self.JobStorageUsernameEdit.setValidator(UsernameAndJobnameValidator(self.JobStorageUsernameEdit))
  937.             self.JobStorageUsernameEdit.setMaxLength(16)
  938.             gridlayout1.addWidget(self.JobStorageUsernameEdit, 0, 2, 1, 1)
  939.             HBoxLayout.addWidget(self.JobStorageUsernameGroupBox)
  940.             self.JobStorageUsernameDefaultButton = QPushButton(self.widget)
  941.             HBoxLayout.addWidget(self.JobStorageUsernameDefaultButton)
  942.             self.JobStorageUsernameAutoRadioButton.setText(self._PrintSettingsToolbox__tr('Automatic'))
  943.             self.JobStorageUsernameCustomRadioButton.setText(self._PrintSettingsToolbox__tr('Custom:'))
  944.             self.JobStorageUsernameDefaultButton.setText(self._PrintSettingsToolbox__tr('Default'))
  945.             self.connect(self.JobStorageUsernameAutoRadioButton, SIGNAL('toggled(bool)'), self.JobStorageUsernameAutoRadioButton_toggled)
  946.             self.connect(self.JobStorageUsernameCustomRadioButton, SIGNAL('toggled(bool)'), self.JobStorageUsernameCustomRadioButton_toggled)
  947.             self.connect(self.JobStorageUsernameDefaultButton, SIGNAL('clicked()'), self.JobStorageUsernameDefaultButton_clicked)
  948.             self.connect(self.JobStorageUsernameEdit, SIGNAL('textEdited(const QString &)'), self.JobStorageUsernameEdit_textEdited)
  949.             self.gridlayout.addLayout(HBoxLayout, self.row, 0, 1, 1)
  950.         elif typ == cups.UI_JOB_STORAGE_ID:
  951.             HBoxLayout = QHBoxLayout()
  952.             HBoxLayout.setObjectName('HBoxLayout')
  953.             OptionLabel = QLabel(self.widget)
  954.             OptionLabel.setObjectName('OptionLabel')
  955.             HBoxLayout.addWidget(OptionLabel)
  956.             OptionLabel.setText(text)
  957.             SpacerItem = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  958.             HBoxLayout.addItem(SpacerItem)
  959.             self.JobStorageIDGroupBox = QFrame(self.widget)
  960.             gridlayout1 = QGridLayout(self.JobStorageIDGroupBox)
  961.             self.JobStorageIDAutoRadioButton = QRadioButton(self.JobStorageIDGroupBox)
  962.             gridlayout1.addWidget(self.JobStorageIDAutoRadioButton, 0, 0, 1, 1)
  963.             self.JobStorageIDCustomRadioButton = QRadioButton(self.JobStorageIDGroupBox)
  964.             gridlayout1.addWidget(self.JobStorageIDCustomRadioButton, 0, 1, 1, 1)
  965.             self.JobStorageIDEdit = QLineEdit(self.JobStorageIDGroupBox)
  966.             self.JobStorageIDEdit.setValidator(UsernameAndJobnameValidator(self.JobStorageIDEdit))
  967.             self.JobStorageIDEdit.setMaxLength(16)
  968.             gridlayout1.addWidget(self.JobStorageIDEdit, 0, 2, 1, 1)
  969.             HBoxLayout.addWidget(self.JobStorageIDGroupBox)
  970.             self.JobStorageIDDefaultButton = QPushButton(self.widget)
  971.             HBoxLayout.addWidget(self.JobStorageIDDefaultButton)
  972.             self.JobStorageIDAutoRadioButton.setText(self._PrintSettingsToolbox__tr('Automatic'))
  973.             self.JobStorageIDCustomRadioButton.setText(self._PrintSettingsToolbox__tr('Custom:'))
  974.             self.JobStorageIDDefaultButton.setText(self._PrintSettingsToolbox__tr('Default'))
  975.             self.connect(self.JobStorageIDAutoRadioButton, SIGNAL('toggled(bool)'), self.JobStorageIDAutoRadioButton_toggled)
  976.             self.connect(self.JobStorageIDCustomRadioButton, SIGNAL('toggled(bool)'), self.JobStorageIDCustomRadioButton_toggled)
  977.             self.connect(self.JobStorageIDDefaultButton, SIGNAL('clicked()'), self.JobStorageIDDefaultButton_clicked)
  978.             self.connect(self.JobStorageIDEdit, SIGNAL('textEdited(const QString &)'), self.JobStorageIDEdit_textEdited)
  979.             self.gridlayout.addLayout(HBoxLayout, self.row, 0, 1, 1)
  980.         elif typ == cups.UI_JOB_STORAGE_ID_EXISTS:
  981.             HBoxLayout = QHBoxLayout()
  982.             HBoxLayout.setObjectName('HBoxLayout')
  983.             OptionLabel = QLabel(self.widget)
  984.             OptionLabel.setObjectName('OptionLabel')
  985.             HBoxLayout.addWidget(OptionLabel)
  986.             OptionLabel.setText(text)
  987.             SpacerItem = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  988.             HBoxLayout.addItem(SpacerItem)
  989.             self.JobStorageExistingComboBox = QComboBox(self.widget)
  990.             HBoxLayout.addWidget(self.JobStorageExistingComboBox)
  991.             self.JobStorageExistingDefaultButton = QPushButton(self.widget)
  992.             HBoxLayout.addWidget(self.JobStorageExistingDefaultButton)
  993.             self.JobStorageExistingComboBox.addItem(self._PrintSettingsToolbox__tr('Replace existing job'), QVariant(JOB_STORAGE_EXISTING_JOB_REPLACE))
  994.             self.JobStorageExistingComboBox.addItem(self._PrintSettingsToolbox__tr('Use job name appended with 1-99'), QVariant(JOB_STORAGE_EXISTING_JOB_APPEND_1_99))
  995.             self.JobStorageExistingDefaultButton.setText(self._PrintSettingsToolbox__tr('Default'))
  996.             self.gridlayout.addLayout(HBoxLayout, self.row, 0, 1, 1)
  997.             self.connect(self.JobStorageExistingComboBox, SIGNAL('activated(int)'), self.JobStorageExistingComboBox_activated)
  998.             self.connect(self.JobStorageExistingDefaultButton, SIGNAL('clicked()'), self.JobStorageExistingDefaultButton_clicked)
  999.         else:
  1000.             log.error('Invalid UI value: %s/%s' % (self.group, option))
  1001.         self.row += 1
  1002.  
  1003.     
  1004.     def BannerComboBox_activated(self, a):
  1005.         a = unicode(a)
  1006.         sender = self.sender()
  1007.         choice = None
  1008.         (start, end) = (None, None)
  1009.         for c, t in sender.choices:
  1010.             if t == a:
  1011.                 start = c
  1012.                 break
  1013.                 continue
  1014.         
  1015.         for c, t in sender.other.choices:
  1016.             if t == sender.other.currentText():
  1017.                 end = c
  1018.                 break
  1019.                 continue
  1020.         
  1021.         if sender.option == 'end':
  1022.             start = end
  1023.             end = start
  1024.         
  1025.         if start is not None and end is not None and start.lower() == sender.default[0].lower() and end.lower() == sender.default[1].lower():
  1026.             self.removePrinterOption('job-sheets')
  1027.             sender.pushbutton.setEnabled(False)
  1028.         else:
  1029.             sender.pushbutton.setEnabled(True)
  1030.             if start is not None and end is not None:
  1031.                 self.setPrinterOption('job-sheets', ','.join([
  1032.                     start,
  1033.                     end]))
  1034.             
  1035.  
  1036.     
  1037.     def ComboBox_highlighted(self, t):
  1038.         t = unicode(t)
  1039.         sender = self.sender()
  1040.         choice = None
  1041.         choice = None
  1042.         for c, a in sender.choices:
  1043.             if a == t:
  1044.                 choice = c
  1045.                 break
  1046.                 continue
  1047.         
  1048.         if choice is not None and choice == sender.default:
  1049.             if sender.job_option:
  1050.                 self.job_options[sender.option] = sender.default
  1051.             else:
  1052.                 self.removePrinterOption(sender.option)
  1053.             sender.pushbutton.setEnabled(False)
  1054.         else:
  1055.             sender.pushbutton.setEnabled(True)
  1056.             if choice is not None:
  1057.                 if sender.job_option:
  1058.                     self.job_options[sender.option] = choice
  1059.                 else:
  1060.                     self.setPrinterOption(sender.option, choice)
  1061.             
  1062.  
  1063.     
  1064.     def SpinBox_valueChanged(self, i):
  1065.         sender = self.sender()
  1066.         if not sender.job_option:
  1067.             if i == sender.default:
  1068.                 self.removePrinterOption(sender.option)
  1069.                 sender.pushbutton.setEnabled(False)
  1070.             else:
  1071.                 sender.pushbutton.setEnabled(True)
  1072.                 self.setPrinterOption(sender.option, str(i))
  1073.         else:
  1074.             
  1075.             try:
  1076.                 self.job_options[sender.option] = int(i)
  1077.             except ValueError:
  1078.                 self.job_options[sender.option] = sender.default
  1079.  
  1080.  
  1081.     
  1082.     def BoolRadioButtons_clicked(self, b):
  1083.         sender = self.sender()
  1084.         b = int(b)
  1085.         if b == sender.default:
  1086.             self.removePrinterOption(sender.option)
  1087.             sender.pushbutton.setEnabled(False)
  1088.         else:
  1089.             sender.pushbutton.setEnabled(True)
  1090.             if b:
  1091.                 self.setPrinterOption(sender.option, 'true')
  1092.             else:
  1093.                 self.setPrinterOption(sender.option, 'false')
  1094.  
  1095.     
  1096.     def DefaultButton_clicked(self):
  1097.         sender = self.sender()
  1098.         sender.setEnabled(False)
  1099.         if sender.typ == cups.PPD_UI_BOOLEAN:
  1100.             if sender.default:
  1101.                 sender.control[0].setChecked(True)
  1102.                 sender.control[0].setFocus(Qt.OtherFocusReason)
  1103.             else:
  1104.                 sender.control[1].setChecked(True)
  1105.                 sender.control[1].setFocus(Qt.OtherFocusReason)
  1106.             if not sender.job_option:
  1107.                 self.removePrinterOption(sender.option)
  1108.             
  1109.         elif sender.typ == cups.PPD_UI_PICKONE:
  1110.             (choice, text) = (None, None)
  1111.             for c, t in sender.choices:
  1112.                 if c == sender.default:
  1113.                     choice = c
  1114.                     text = t
  1115.                     self.job_options[sender.option] = t
  1116.                     break
  1117.                     continue
  1118.             
  1119.             if choice is not None:
  1120.                 if not sender.job_option:
  1121.                     self.removePrinterOption(sender.option)
  1122.                 
  1123.                 index = sender.control.findText(text)
  1124.                 sender.control.setCurrentIndex(index)
  1125.                 sender.control.setFocus(Qt.OtherFocusReason)
  1126.             
  1127.         elif sender.typ == cups.UI_SPINNER:
  1128.             sender.control.setValue(sender.default)
  1129.             if not sender.job_option:
  1130.                 self.removePrinterOption(sender.option)
  1131.             
  1132.             sender.control.setFocus(Qt.OtherFocusReason)
  1133.         elif sender.typ == cups.UI_BANNER_JOB_SHEETS:
  1134.             (start, end, start_text, end_text) = (None, None, None, None)
  1135.             for c, t in sender.choices:
  1136.                 if c == sender.default[0]:
  1137.                     start = c
  1138.                     start_text = t
  1139.                 
  1140.                 if c == sender.default[1]:
  1141.                     end = c
  1142.                     end_text = t
  1143.                     continue
  1144.             
  1145.             if start is not None:
  1146.                 index = sender.control[0].findText(start_text)
  1147.                 sender.control[0].setCurrentIndex(index)
  1148.             
  1149.             if end is not None:
  1150.                 index = sender.control[1].findText(end_text)
  1151.                 sender.control[1].setCurrentIndex(index)
  1152.             
  1153.             if not sender.job_option:
  1154.                 self.removePrinterOption('job-sheets')
  1155.             
  1156.             sender.control[0].setFocus(Qt.OtherFocusReason)
  1157.         elif sender.typ == cups.UI_PAGE_RANGE:
  1158.             sender.control[0].setChecked(True)
  1159.             sender.control[0].setFocus(Qt.OtherFocusReason)
  1160.             sender.control[2].setEnabled(False)
  1161.         
  1162.  
  1163.     
  1164.     def PageRangeAllRadio_toggled(self, b):
  1165.         if b:
  1166.             sender = self.sender()
  1167.             sender.edit_control.setEnabled(False)
  1168.             sender.pushbutton.setEnabled(False)
  1169.             self.job_options['pagerange'] = ''
  1170.         
  1171.  
  1172.     
  1173.     def PageRangeRangeRadio_toggled(self, b):
  1174.         if b:
  1175.             sender = self.sender()
  1176.             sender.pushbutton.setEnabled(True)
  1177.             sender.edit_control.setEnabled(True)
  1178.             self.job_options['pagerange'] = unicode(sender.edit_control.text())
  1179.         
  1180.  
  1181.     
  1182.     def PageRangeEdit_editingFinished(self):
  1183.         sender = self.sender()
  1184.         x = []
  1185.         t = unicode(sender.text())
  1186.         ok = True
  1187.         
  1188.         try:
  1189.             x = utils.expand_range(t)
  1190.         except ValueError:
  1191.             ok = False
  1192.  
  1193.         if ok:
  1194.             if 0 in x:
  1195.                 ok = False
  1196.             
  1197.             if ok:
  1198.                 for y in x:
  1199.                     if y > 999:
  1200.                         ok = False
  1201.                         break
  1202.                         continue
  1203.                 
  1204.             
  1205.         
  1206.         if ok:
  1207.             t = utils.collapse_range(x)
  1208.             sender.setText(QString(t))
  1209.             self.job_options['pagerange'] = t
  1210.         else:
  1211.             self.job_options['pagerange'] = ''
  1212.             log.error('Invalid page range: %s' % t)
  1213.             FailureUI(self, self._PrintSettingsToolbox__tr('<b>Invalid page range.</b><p>Please enter a range using page numbers (1-999), dashes, and commas. For example: 1-2,3,5-7</p>'))
  1214.             sender.setFocus(Qt.OtherFocusReason)
  1215.  
  1216.     
  1217.     def PageRangeEdit_textChanged(self, t):
  1218.         sender = self.sender()
  1219.         x = []
  1220.         t = unicode(t)
  1221.         
  1222.         try:
  1223.             x = utils.expand_range(t)
  1224.         except ValueError:
  1225.             self.job_options['pagerange'] = ''
  1226.             log.error('Invalid page range: %s' % t)
  1227.  
  1228.         self.job_options['pagerange'] = t
  1229.  
  1230.     
  1231.     def updateJobStorageControls(self):
  1232.         beginWaitCursor()
  1233.         
  1234.         try:
  1235.             self.JobStorageModeComboBox.setCurrentIndex(self.JobStorageModeComboBox.findData(QVariant(self.job_storage_mode)))
  1236.             self.JobStorageModeDefaultButton.setEnabled(self.job_storage_mode != JOB_STORAGE_TYPE_OFF)
  1237.             self.JobStoragePinPrivateRadioButton.setChecked(self.job_storage_use_pin)
  1238.             self.JobStorageUsernameAutoRadioButton.setChecked(self.job_storage_auto_username)
  1239.             self.JobStorageIDAutoRadioButton.setChecked(self.job_storage_auto_jobname)
  1240.             self.JobStorageExistingComboBox.setCurrentIndex(self.JobStorageExistingComboBox.findData(QVariant(self.job_storage_job_exist)))
  1241.             if self.job_storage_mode == JOB_STORAGE_TYPE_OFF:
  1242.                 self.JobStoragePinGroupBox.setEnabled(False)
  1243.                 self.JobStoragePinEdit.setEnabled(False)
  1244.                 self.JobStoragePinDefaultButton.setEnabled(False)
  1245.                 self.JobStoragePinEdit.setText(QString())
  1246.                 self.JobStorageUsernameGroupBox.setEnabled(False)
  1247.                 self.JobStorageUsernameEdit.setEnabled(False)
  1248.                 self.JobStorageUsernameDefaultButton.setEnabled(False)
  1249.                 self.JobStorageIDGroupBox.setEnabled(False)
  1250.                 self.JobStorageIDEdit.setEnabled(False)
  1251.                 self.JobStorageIDDefaultButton.setEnabled(False)
  1252.                 self.JobStorageExistingComboBox.setEnabled(False)
  1253.             elif self.job_storage_mode in (JOB_STORAGE_TYPE_PERSONAL, JOB_STORAGE_TYPE_STORE):
  1254.                 self.JobStoragePinGroupBox.setEnabled(True)
  1255.                 self.JobStoragePinDefaultButton.setEnabled(self.job_storage_use_pin)
  1256.                 self.JobStoragePinEdit.setEnabled(self.job_storage_use_pin)
  1257.                 self.JobStoragePinEdit.setText(QString(self.job_storage_pin))
  1258.             else:
  1259.                 self.JobStoragePinGroupBox.setEnabled(False)
  1260.                 self.JobStoragePinEdit.setEnabled(False)
  1261.                 self.JobStoragePinDefaultButton.setEnabled(False)
  1262.                 self.JobStoragePinEdit.setText(QString())
  1263.             self.JobStorageUsernameGroupBox.setEnabled(True)
  1264.             self.JobStorageUsernameEdit.setEnabled(not (self.job_storage_auto_username))
  1265.             self.JobStorageUsernameDefaultButton.setEnabled(not (self.job_storage_auto_username))
  1266.             self.JobStorageUsernameEdit.setText(QString(self.job_storage_username))
  1267.             self.JobStorageIDGroupBox.setEnabled(True)
  1268.             self.JobStorageIDEdit.setEnabled(not (self.job_storage_auto_jobname))
  1269.             self.JobStorageIDDefaultButton.setEnabled(not (self.job_storage_auto_jobname))
  1270.             self.JobStorageIDEdit.setText(QString(self.job_storage_jobname))
  1271.             self.JobStorageExistingComboBox.setEnabled(not (self.job_storage_auto_jobname))
  1272.             if not (self.job_storage_auto_jobname):
  1273.                 pass
  1274.             self.JobStorageExistingDefaultButton.setEnabled(self.job_storage_job_exist != JOB_STORAGE_EXISTING_JOB_REPLACE)
  1275.         finally:
  1276.             endWaitCursor()
  1277.  
  1278.  
  1279.     
  1280.     def saveJobStorageOptions(self):
  1281.         beginWaitCursor()
  1282.         
  1283.         try:
  1284.             log.debug('Saving job storage options...')
  1285.             if self.job_storage_mode == JOB_STORAGE_TYPE_OFF:
  1286.                 log.debug('Job storage mode = JOB_STORAGE_TYPE_OFF')
  1287.                 self.setPrinterOption('HOLD', 'OFF')
  1288.                 self.removePrinterOption('HOLDTYPE')
  1289.                 self.removePrinterOption('USERNAME')
  1290.                 self.removePrinterOption('JOBNAME')
  1291.                 self.removePrinterOption('DUPLICATEJOB')
  1292.             elif self.job_storage_mode == JOB_STORAGE_TYPE_PROOF_AND_HOLD:
  1293.                 log.debug('Job storage mode = JOB_STORAGE_TYPE_PROOF_AND_HOLD')
  1294.                 self.setPrinterOption('HOLD', 'PROOF')
  1295.                 self.setPrinterOption('HOLDTYPE', 'PUBLIC')
  1296.             elif self.job_storage_mode == JOB_STORAGE_TYPE_PERSONAL:
  1297.                 log.debug('Job storage mode = JOB_STORAGE_TYPE_PERSONAL')
  1298.                 if self.job_storage_use_pin:
  1299.                     self.setPrinterOption('HOLD', 'ON')
  1300.                 else:
  1301.                     self.setPrinterOption('HOLD', 'PROOF')
  1302.                     self.setPrinterOption('HOLDTYPE', 'PUBLIC')
  1303.             elif self.job_storage_mode == JOB_STORAGE_TYPE_QUICK_COPY:
  1304.                 log.debug('Job storage mode = JOB_STORAGE_TYPE_QUICK_COPY')
  1305.                 self.setPrinterOption('HOLD', 'ON')
  1306.                 self.setPrinterOption('HOLDTYPE', 'PUBLIC')
  1307.             elif self.job_storage_mode == JOB_STORAGE_TYPE_STORE:
  1308.                 log.debug('Job storage mode = JOB_STORAGE_TYPE_STORE')
  1309.                 self.setPrinterOption('HOLD', 'STORE')
  1310.                 if not self.job_storage_use_pin:
  1311.                     self.removePrinterOption('HOLDTYPE')
  1312.                 
  1313.             
  1314.             log.debug('Job storage use pin = %d' % self.job_storage_use_pin)
  1315.             if self.job_storage_use_pin:
  1316.                 self.setPrinterOption('HOLDTYPE', 'PRIVATE')
  1317.             
  1318.             if self.job_storage_job_exist == JOB_STORAGE_EXISTING_JOB_REPLACE:
  1319.                 log.debug('Job storage duplicate = JOB_STORAGE_EXISTING_JOB_REPLACE')
  1320.                 self.setPrinterOption('DUPLICATEJOB', 'REPLACE')
  1321.             else:
  1322.                 log.debug('Job storage duplicate = JOB_STORAGE_EXISTING_JOB_APPEND_1_99')
  1323.                 self.setPrinterOption('DUPLICATEJOB', 'APPEND')
  1324.         finally:
  1325.             endWaitCursor()
  1326.  
  1327.  
  1328.     
  1329.     def JobStorageModeComboBox_activated(self, i):
  1330.         sender = self.sender()
  1331.         (mode, ok) = sender.itemData(i).toInt()
  1332.         if ok:
  1333.             self.job_storage_mode = mode
  1334.             self.saveJobStorageOptions()
  1335.             self.updateJobStorageControls()
  1336.         
  1337.  
  1338.     
  1339.     def JobStorageModeDefaultButton_clicked(self):
  1340.         self.JobStorageModeComboBox.emit(SIGNAL('activated(int)'), JOB_STORAGE_TYPE_OFF)
  1341.  
  1342.     
  1343.     def JobStoragePinOffRadioButton_toggled(self, b):
  1344.         self.job_storage_use_pin = not b
  1345.         self.updateJobStorageControls()
  1346.         self.saveJobStorageOptions()
  1347.  
  1348.     
  1349.     def JobStoragePinPrivateRadioButton_toggled(self, b):
  1350.         self.job_storage_use_pin = b
  1351.         self.updateJobStorageControls()
  1352.         self.saveJobStorageOptions()
  1353.  
  1354.     
  1355.     def JobStoragePinDefaultButton_clicked(self):
  1356.         self.JobStoragePinOffRadioButton.emit(SIGNAL('toggled(bool)'), True)
  1357.  
  1358.     
  1359.     def JobStoragePinEdit_textEdited(self, s):
  1360.         self.job_storage_pin = unicode(s)
  1361.         self.setPrinterOption('HOLDKEY', self.job_storage_pin.encode('ascii'))
  1362.  
  1363.     
  1364.     def JobStorageUsernameAutoRadioButton_toggled(self, b):
  1365.         self.job_storage_auto_username = b
  1366.         self.updateJobStorageControls()
  1367.         self.saveJobStorageOptions()
  1368.  
  1369.     
  1370.     def JobStorageUsernameCustomRadioButton_toggled(self, b):
  1371.         self.job_storage_auto_username = not b
  1372.         self.updateJobStorageControls()
  1373.         self.saveJobStorageOptions()
  1374.  
  1375.     
  1376.     def JobStorageUsernameDefaultButton_clicked(self):
  1377.         self.JobStorageUsernameAutoRadioButton.emit(SIGNAL('toggled(bool)'), True)
  1378.  
  1379.     
  1380.     def JobStorageUsernameEdit_textEdited(self, s):
  1381.         self.job_storage_username = unicode(s)
  1382.         self.setPrinterOption('USERNAME', self.job_storage_username.encode('ascii'))
  1383.  
  1384.     
  1385.     def JobStorageIDAutoRadioButton_toggled(self, b):
  1386.         self.job_storage_auto_jobname = b
  1387.         self.updateJobStorageControls()
  1388.         self.saveJobStorageOptions()
  1389.  
  1390.     
  1391.     def JobStorageIDCustomRadioButton_toggled(self, b):
  1392.         self.job_storage_auto_jobname = not b
  1393.         self.updateJobStorageControls()
  1394.         self.saveJobStorageOptions()
  1395.  
  1396.     
  1397.     def JobStorageIDDefaultButton_clicked(self):
  1398.         self.JobStorageIDAutoRadioButton.emit(SIGNAL('toggled(bool)'), True)
  1399.  
  1400.     
  1401.     def JobStorageIDEdit_textEdited(self, s):
  1402.         self.job_storage_jobname = unicode(s)
  1403.         self.setPrinterOption('JOBNAME', self.job_storage_jobname.encode('ascii'))
  1404.  
  1405.     
  1406.     def JobStorageExistingComboBox_activated(self, i):
  1407.         sender = self.sender()
  1408.         (opt, ok) = sender.itemData(i).toInt()
  1409.         if ok:
  1410.             self.job_storage_job_exist = opt
  1411.             self.updateJobStorageControls()
  1412.             self.saveJobStorageOptions()
  1413.         
  1414.  
  1415.     
  1416.     def JobStorageExistingDefaultButton_clicked(self):
  1417.         self.JobStorageExistingComboBox.emit(SIGNAL('activated(int)'), JOB_STORAGE_EXISTING_JOB_REPLACE)
  1418.  
  1419.     
  1420.     def setPrinterOption(self, option, value):
  1421.         log.debug('setPrinterOption(%s, %s)' % (option, value))
  1422.         cups.openPPD(self.cur_printer)
  1423.         
  1424.         try:
  1425.             cups.addOption('%s=%s' % (option, value))
  1426.             cups.setOptions()
  1427.         finally:
  1428.             cups.closePPD()
  1429.  
  1430.  
  1431.     
  1432.     def removePrinterOption(self, option):
  1433.         log.debug('removePrinterOption(%s)' % option)
  1434.         cups.openPPD(self.cur_printer)
  1435.         
  1436.         try:
  1437.             cups.removeOption(option)
  1438.             cups.setOptions()
  1439.         finally:
  1440.             cups.closePPD()
  1441.  
  1442.  
  1443.     
  1444.     def __tr(self, s, c = None):
  1445.         return qApp.translate('PrintSettingsToolbox', s, c)
  1446.  
  1447.  
  1448.